<?php

class AbstractModel extends Zend_Db_Table
{
	
	protected $_fieldsToDisplay = array('id');
	protected $_hasCreationDate = false;
	protected $_hasModificationDate = false;
	
	/**
	 * 
	 * Get a SQL row and returns an array with te wanted fields
	 * @param Zend_Db_Table_Row $row
	 * @param array $fields
	 */ 
	public function getArrayFromRow($row) {
		$result = array();
		foreach ($this->_fieldsToDisplay as $key) {
			$result[$key] = $row->$key;
		}
    	return $result;
	}
	
	
    public function insert(array $data)
    {
    	if ($this->_hasCreationDate && empty($data['creation_date'])) {
	        // Ajout d'un timestamp
            $data['creation_date'] = time();
    	}
    	if ($this->_hasModificationDate && empty($data['modification_date'])) {
            $data['modification_date'] = time();
    	}
        return parent::insert($data);
    }
 
    public function update(array $data, $where)
    {
    	if ($this->_hasModificationDate && empty($data['modification_date'])) {
            $data['modification_date'] = time();
    	}
  	    return parent::update($data, $where);
    }
}
